package com.welink.cmp.dao.metadata;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.welink.cmp.dao.metadata.dataobject.RouterDO;
import com.welink.cmp.dto.metadata.router.query.RouterListByPageQry;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * 路由器 Dao Service
 * 提供路由器的CRUD操作
 *
 * @authoryanwei li
 * @create 2024-05-20 21:23
 */
@Component
public class RouterDaoService extends ServiceImpl<RouterMapper, RouterDO> {

    /**
     * 保存或更新路由器信息
     *
     * @param routerDO 路由器数据对象
     * @return 是否保存或更新成功
     */
    public boolean saveOrUpdateRouter(RouterDO routerDO) {
        return this.saveOrUpdate(routerDO);
    }

    /**
     * 根据ID查询路由器信息
     *
     * @param id 路由器ID
     * @return 路由器数据对象
     */
    public RouterDO getRouterById(Long id) {
        return this.getById(id);
    }

    public Page<RouterDO> pageQry(RouterListByPageQry pageQry) {
        Page<RouterDO> page = new Page<>(pageQry.getPageIndex(), pageQry.getPageSize());
        LambdaQueryWrapper<RouterDO> wrapper = new LambdaQueryWrapper<>();
        if (pageQry.getName() != null) {
            wrapper.eq(RouterDO::getVendor, pageQry.getName());
        }
        if (pageQry.getStrCreateTime() != null) {
            wrapper.ge(RouterDO::getCreateTime, pageQry.getStrCreateTime());
        }
        if (pageQry.getEndCreateTime() != null) {
            wrapper.le(RouterDO::getCreateTime, pageQry.getEndCreateTime());
        }
        return this.page(page, wrapper);
    }
}
